{extend name="base" /}
{block name="content"}
<div class="content">
    <div class="container-fluid">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-12">
                <div class="page-title-box">
                    <div class="page-title-right">
                        <ol class="breadcrumb m-0">
                            <li class="breadcrumb-item"><a href="{:url('index/index')}"><i class="fe-home"></i> 控制台</a></li>
                            <li class="breadcrumb-item active"> Add Campaign Type</li>
                        </ol>
                    </div>
                <h4 class="page-title"> 
                    <button onClick="javascript:history.go(-1)" type="button" class="btn btn-xs btn-secondary waves-effect waves-light">
                            <i class="fe-corner-up-left"></i> 返回
                    </button>
                    Add Campaign Type </h4>
                </div>
            </div>
        </div>
        <div class="row">
        <div class="col-lg-8 col-md-6">
            <div class="card-box">
                    <form id="form1">
                    <br/>
                    <div class="form-group row">
                        <label for="user" class="col-2 col-form-label">分类名称</label>
                        <div class="col-6">
                            <input type="text" class="form-control" id="name" placeholder="分类名称" name="name">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="user" class="col-2 col-form-label">分类Banner</label>
                        <div class="col-9">
                            <img class=" vatar-xl" id="pic_url" style="margin-bottom: 10px; width: 50%"><br/>
                            <input type="hidden" class="form-control" id="pic" placeholder="上传后显示" name="pic"  readonly>
                            <button type="button" class="layui-btn layui-btn-xs" id="test1"> 
                                <i class="layui-icon">&#xe67c;</i>上传图片
                            </button>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="user" class="col-2 col-form-label">分类排序</label>
                        <div class="col-6">
                            <input type="text" class="form-control" id="sort" placeholder="分类排序" value="50" name="sort">
                        </div>
                    </div>
                    <div class="form-group mb-5 justify-content-end row">
                        <div class="col-10">
                             <a class="btn btn-info waves-effect waves-light" style="color: #fff" data-ids="1" onclick="postBtn(this)" >提交</a>
                        </div>
                    </div>
                    </form>
                </div>
            </div>
        </div>
    </div> <!-- container -->
</div> <!-- content -->
<script src="/static/layui/layui.js"></script>
<script>
    layui.use(['element', 'form', 'layedit','upload'], function () {
        var form = layui.form;
        var $ = layui.jquery,upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '/admin/index/uploadFile'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#pic_url').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
                console.log(res.data.src)
                $('#pic').val(res.data.src);
            }
            ,error: function(){
                //演示失败状态，并实现重传
                return layer.msg('上传失败');
            }
        });

    })
</script>
<script>
    layui.use(['element', 'form', 'layedit','upload'], function () {
        var form = layui.form;
        var $ = layui.jquery,upload = layui.upload;
    })

    function postBtn(e){
        var data = $('#form1').serialize();
        $.post('/admin/campaigntp/add', data, function(res){
            if(res.code == 0){
                layer.msg(res.message,{icon:1, time:1000, shade: [0.2, '#000']});
                setTimeout(function(){
                    window.location.href=res.data.url;
                },1000);
            }else{
                layer.msg(res.message,{icon:5, anim: 6, time:1000, shade: [0.2, '#000']});
            }
        },'json');
    }
</script>
{/block}